<!DOCTYPE html>
<html lang="en">
<head>
    <th:block th:include="include :: header('序列号方案选项')" />
</head>
<body>
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>模块名称：</label>
                            <input type="text" name="moduleName"/>
                        </li>
                        <li>
                            <label>模块编码：</label>
                            <input type="text" name="moduleCode"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer" />
<script th:inline="javascript">

    const prefix = ctx + "system/serialNumber"
    let activeSerialNumber = null;

    $(function() {
        var options = {
            requestPrefix: prefix,
            uniqueId:'id',
            modalName: "序列号模板",
            signName: "sys_serial_number",
            queryParams:{
                state:state.OK,
            },onCheck(rowData){
                activeSerialNumber = rowData
            },onUncheck(rowData){
                activeSerialNumber = null
            },onDblClickRow(rowData){
                activeSerialNumber = rowData
                submitHandler()
            },
            columns: [
                {
                radio: true
                },
                {
                    field: 'id',
                    title: '编号',
                    visible: false,
                    sortable:true,
                },
                {
                    field: 'moduleName',
                    title: '模块名称',
                    sortable:true,
                    formatter: function(value,row,index){
                        return $.table.tooltip(value);
                    }
                },
                {
                    field: 'moduleCode',
                    title: '模块编码',
                    sortable:true,
                    formatter: function(value,row,index){
                        return $.table.tooltip(value);
                    }
                },
                {
                    field: 'count',
                    title: '流水号大小',
                    sortable:true,
                    formatter: function(value,row,index){
                        return $.table.tooltip(value);
                    }
                },
                {
                    field: 'createTime',
                    title: '创建时间',
                    sortable:true,
                    visible: false,
                    formatter: function(value,row,index){
                        return $.table.tooltip(value);
                    }
                }]
        };
        $.table.init(options);
    });

    function submitHandler(index, layero,callback) {
        if(activeSerialNumber){
            $.axiosRequest.get(prefix+"/getMaxSerialNumber/"+activeSerialNumber.moduleCode)
                .then(res=>{
                    if(callback && typeof callback =='function'){
                        callback(res.data)
                    }
                    $.modal.close();
                })
            $.modal.close();
        }else{
            $.modal.msgError('请选择序列号方案！')
        }
    }

</script>
</body>
</html>